/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frm_JInternalFrameLapHoaDonBanSach.java
 *
 * Created on Aug 2, 2011, 6:09:42 PM
 */
package gui;


import dao.ChiTietHoaDonDAO;
import dao.HoaDonDAO;
import dao.SachDAO;
import java.util.ArrayList;
import java.util.Date;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import pojo.ChiTietHoaDonPOJO;
import pojo.HoaDonPOJO;
import pojo.SachPOJO;

/**
 *
 * @author HP
 */
public class frm_JInternalFrameLapHoaDonBanSach extends javax.swing.JInternalFrame {

    private DefaultTableModel tablemodelgiohang;
    private DefaultTableModel tablemodelSach;
    ArrayList<SachPOJO> dsSach = new ArrayList<SachPOJO>();
    ArrayList<ChiTietHoaDonPOJO> giohang = new ArrayList<ChiTietHoaDonPOJO>();
    SachDAO sachdao = new SachDAO();
    int stt = 1;

    /** Creates new form frm_JInternalFrameLapHoaDonBanSach */
    public frm_JInternalFrameLapHoaDonBanSach() {
        initComponents();
        tablemodelSach = new DefaultTableModel();
        this.tablemodelSach.addColumn("STT");
        this.tablemodelSach.addColumn("Ma Sach");
        this.tablemodelSach.addColumn("Ten Sach");
        this.tablemodelSach.addColumn("Gia Ban");
        this.jtbDSSach.setModel(tablemodelSach);


        tablemodelgiohang = new DefaultTableModel();
        this.tablemodelgiohang.addColumn("STT");
        this.tablemodelgiohang.addColumn("Ma Sach");
        this.tablemodelgiohang.addColumn("Ten Sach");
        this.tablemodelgiohang.addColumn("So Luong ");
        this.tablemodelgiohang.addColumn("Gia Ban");
        this.tablemodelgiohang.addColumn("Thanh Tien");
        this.jtbGioHang.setModel(tablemodelgiohang);
        HienThiDanhSachSach(1);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jPanelDSSach = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtbDSSach = new javax.swing.JTable();
        jPanel4 = new javax.swing.JPanel();
        jbtnDatHang = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtxtMaSach = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jtxtTenSach = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jtxtGiaBan = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jtxtSoLuongMua = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jtxtTongTien = new javax.swing.JTextField();
        jbtnThemGioHang = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtbGioHang = new javax.swing.JTable();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Lap Hoa Don Ban Sach");

        jPanel1.setBackground(new java.awt.Color(255, 204, 255));

        jPanel2.setBackground(new java.awt.Color(204, 204, 255));

        jLabel6.setFont(new java.awt.Font("Tahoma", 3, 24));
        jLabel6.setText("Chọn Giỏ Hàng");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(453, Short.MAX_VALUE)
                .addComponent(jLabel6)
                .addGap(391, 391, 391))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jLabel6)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanelDSSach.setBackground(new java.awt.Color(204, 204, 255));
        jPanelDSSach.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 51, 204), 2), "Danh Sach Sach"));

        jtbDSSach.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jtbDSSach.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtbDSSachMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(jtbDSSach);

        javax.swing.GroupLayout jPanelDSSachLayout = new javax.swing.GroupLayout(jPanelDSSach);
        jPanelDSSach.setLayout(jPanelDSSachLayout);
        jPanelDSSachLayout.setHorizontalGroup(
            jPanelDSSachLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 499, Short.MAX_VALUE)
        );
        jPanelDSSachLayout.setVerticalGroup(
            jPanelDSSachLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 438, Short.MAX_VALUE)
        );

        jPanel4.setBackground(new java.awt.Color(204, 204, 255));
        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 204), 2), "Thong Tin Nhap"));

        jbtnDatHang.setText("Dat Hang");
        jbtnDatHang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnDatHangActionPerformed(evt);
            }
        });

        jPanel6.setBackground(new java.awt.Color(204, 204, 255));

        jLabel1.setText("Ma Sach");

        jtxtMaSach.setFont(new java.awt.Font("Tahoma", 1, 11));
        jtxtMaSach.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        jtxtMaSach.setEnabled(false);

        jLabel2.setText("Ten Sach");

        jtxtTenSach.setFont(new java.awt.Font("Tahoma", 1, 11));
        jtxtTenSach.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        jtxtTenSach.setEnabled(false);

        jLabel3.setText("Gia Ban");

        jtxtGiaBan.setFont(new java.awt.Font("Tahoma", 1, 11));
        jtxtGiaBan.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        jtxtGiaBan.setEnabled(false);

        jLabel4.setText("So Luong Mua");

        jtxtSoLuongMua.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                jtxtSoLuongMuaCaretUpdate(evt);
            }
        });
        jtxtSoLuongMua.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtSoLuongMuaActionPerformed(evt);
            }
        });
        jtxtSoLuongMua.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                jtxtSoLuongMuaInputMethodTextChanged(evt);
            }
        });

        jLabel5.setText("Tong Tien");

        jtxtTongTien.setFont(new java.awt.Font("Tahoma", 1, 11));
        jtxtTongTien.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        jtxtTongTien.setEnabled(false);

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5))
                .addGap(59, 59, 59)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtxtTongTien, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtxtSoLuongMua, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtxtGiaBan, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtxtTenSach, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtxtMaSach, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jtxtMaSach, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jtxtTenSach, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jtxtGiaBan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jtxtSoLuongMua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jtxtTongTien, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(40, Short.MAX_VALUE))
        );

        jbtnThemGioHang.setText("Them Gio Hang");
        jbtnThemGioHang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnThemGioHangActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jbtnDatHang, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jbtnThemGioHang, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(38, 38, 38))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jbtnThemGioHang, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(53, 53, 53)
                        .addComponent(jbtnDatHang, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jPanel5.setBackground(new java.awt.Color(204, 204, 255));
        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 204), 2), "Gio Hang Da Chon"));

        jtbGioHang.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(jtbGioHang);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 472, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 210, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelDSSach, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jPanelDSSach, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jtbDSSachMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtbDSSachMouseClicked
        // TODO add your handling code here:
        try {
            int vt = jtbDSSach.getSelectedRow();

            //int ma= Integer.parseInt(jtbDSSach.getValueAt(vt, 1).toString().trim());
            jtxtMaSach.setText(jtbDSSach.getValueAt(vt, 1).toString().trim());
            jtxtTenSach.setText(jtbDSSach.getValueAt(vt, 2).toString().trim());
            jtxtGiaBan.setText(jtbDSSach.getValueAt(vt, 3).toString().trim());
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), "Đã xảy ra lỗi", JOptionPane.ERROR_MESSAGE);
        }

    }//GEN-LAST:event_jtbDSSachMouseClicked

    private void xoatable() {
        javax.swing.table.DefaultTableModel mode = (DefaultTableModel) this.jtbGioHang.getModel();
        for (int i = 0; i < mode.getRowCount(); i++) {
            mode.removeRow(i);
        }
    }
    private void jtxtSoLuongMuaInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_jtxtSoLuongMuaInputMethodTextChanged
        // TODO add your handling code here:
        try {
            int soluongnhap = Integer.parseInt(jtxtSoLuongMua.getText());
            float dongia = Float.parseFloat(jtxtGiaBan.getText());
            float tongtien = soluongnhap * dongia;
            jtxtTongTien.setText(String.valueOf(tongtien));
        } catch (Exception ex) {
            jtxtTongTien.setText("");
            JOptionPane.showMessageDialog(this, ex.getMessage(), "Đã xảy ra lỗi", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jtxtSoLuongMuaInputMethodTextChanged

    private void jbtnThemGioHangActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnThemGioHangActionPerformed
        // TODO add your handling code here:
        try {
            int soluongnhap = Integer.parseInt(jtxtSoLuongMua.getText());
            float dongia = Float.parseFloat(jtxtGiaBan.getText());
            float tongtien = soluongnhap * dongia;
            jtxtTongTien.setText(String.valueOf(tongtien));

            Vector v = new Vector();
            v.add(stt);
            v.add(jtxtMaSach.getText());
            v.add(jtxtTenSach.getText());
            v.add(jtxtSoLuongMua.getText());
            v.add(jtxtGiaBan.getText());
            v.add(String.valueOf(tongtien));
            this.tablemodelgiohang.addRow(v);


            ChiTietHoaDonPOJO cthd = new ChiTietHoaDonPOJO();
            cthd.setMaSach(jtxtMaSach.getText());
            cthd.setGiaBan(dongia);
            cthd.setSoLuongBan(soluongnhap);
            giohang.add(cthd);
            stt++;

            this.jtxtGiaBan.setText("");
            this.jtxtMaSach.setText("");
            this.jtxtSoLuongMua.setText("");
            this.jtxtTenSach.setText("");
            this.jtxtTongTien.setText("");
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), "Đã xảy ra lỗi", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jbtnThemGioHangActionPerformed

    private void jbtnDatHangActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnDatHangActionPerformed
        // TODO add your handling code here:
        try {
            HoaDonDAO hddao = new HoaDonDAO();
            HoaDonPOJO hddto = new HoaDonPOJO();
            float tongtien = 0;
            for (ChiTietHoaDonPOJO i : giohang) {
                tongtien += i.getGiaBan() * i.getSoLuongBan();
            }
            hddto.setTongTien(tongtien);
            Date d = new Date();
            hddto.setNgayLapHoaDon(d);
            if (hddao.themHoaDon(hddto) == true) {
                ChiTietHoaDonDAO cthdbus = new ChiTietHoaDonDAO();
                int mahoadon = hddao.layMaxMaHoaDon();
                for (ChiTietHoaDonPOJO i : giohang) {
                    i.setMaHoaDon(mahoadon);
                    cthdbus.themChiTietHoaDon(i);
                }

                xoatable();
                JOptionPane.showMessageDialog(this, "Bạn đã đặt thành công", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), "Đã xảy ra lỗi", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jbtnDatHangActionPerformed

    private void jtxtSoLuongMuaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtxtSoLuongMuaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtxtSoLuongMuaActionPerformed

    private void jtxtSoLuongMuaCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jtxtSoLuongMuaCaretUpdate
        // TODO add your handling code here:
        try {
            int soluongnhap = Integer.parseInt(jtxtSoLuongMua.getText());
            float dongia = Float.parseFloat(jtxtGiaBan.getText());
            float tongtien = soluongnhap * dongia;
            jtxtTongTien.setText(String.valueOf(tongtien));
        } catch (Exception ex) {
            jtxtTongTien.setText("");
            //JOptionPane.showMessageDialog(this, ex.getMessage(),"Đã xảy ra lỗi",JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jtxtSoLuongMuaCaretUpdate

    private void HienThiDanhSachSach(int matheloai) {
        dsSach = sachdao.layDanhSachCacMaSach();

        jtbDSSach.removeAll();
        javax.swing.table.DefaultTableModel mode = (DefaultTableModel) this.jtbDSSach.getModel();
        int t = 1;
        for (SachPOJO i : dsSach) {
            mode.addRow(new Object[]{t, i.getMaSach(), i.getTenSach(), i.getGiaBan()});
            t++;
        }

    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanelDSSach;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton jbtnDatHang;
    private javax.swing.JButton jbtnThemGioHang;
    private javax.swing.JTable jtbDSSach;
    private javax.swing.JTable jtbGioHang;
    private javax.swing.JTextField jtxtGiaBan;
    private javax.swing.JTextField jtxtMaSach;
    private javax.swing.JTextField jtxtSoLuongMua;
    private javax.swing.JTextField jtxtTenSach;
    private javax.swing.JTextField jtxtTongTien;
    // End of variables declaration//GEN-END:variables
}
